import { RouteRecordRaw, createRouter, createWebHashHistory } from "vue-router";
import { RouterType } from "../tool/types";

export const routerPlugn: RouterType[] = [
    {
        path: "/",
        component: () => import('../index/index.vue'),
        children: [
            {
                path: "/order",
                component: () => import("@/index/company/order.vue")
            },
            {
                path:"/person",
                component: ()=> import("@/index/person/index.vue")
            },
            {
                path:"/aboutus",
                name:"关于我们",
                component: ()=> import("@/index/person/aboutus.vue")
            },
            {
                path: "/cart",
                name:"购物车",
                component: () => import("@/index/company/cart.vue")
            },
            {
                path: "/upload",
                name:"封面上传",
                component: () => import("@/index/company/upload.vue")
            },
            {
                path: "/menu",
                name:"菜单管理",
                component: () => import("@/index/company/menu.vue")
            },
          
        ]
    },
    {
        path: "/login",
        component: () => import('../index/login.vue'),
        children: []
    },
]

export const router = createRouter({
    history: createWebHashHistory(),
    routes: (routerPlugn as RouteRecordRaw[])
})

router.beforeEach((to, _, next) => {
    if (to.matched.length == 0) {
        router.push("/")
    } else {
        next()
    }
});